#ifndef TRANSFILE_H
#define TRANSFILE_H

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <openssl/sha.h>
#include <openssl/opensslv.h>
#include <openssl/evp.h>
#include <sys/stat.h>
#include <unistd.h>


//第一版上传方的发送：hash,文件名,之后收一个返回值，服务端完成哈希查找是否文件已经存在，判断要不要后续再传
//      下载方的发送：filename
#define train_size (sizeof(train.type)+sizeof(train.length)+train.length)

enum operation{
    //0~10特殊操作，错误返回之类的
    //11~20目录操作
    //21~30文件操作
    //31~40SQL操作
    //一些名字加了下划线是因为某一部分单独是关键字

    return_result=2,

    cd_oreder=11,
    ls_order=12,
    pwd_der=13,
    mkdir_order=14,
    rmdir_order=15,

    puts_file=21,
    file_hash=22,
    file_name=23,
    cur_size=24,
    gets_file=25,
    remove_file=26,
    dont_send=27,
    go_send=28,
    file_txt=29,

    salt=31,
    register_user=32,
    login=33
};

typedef struct train{
    int type;
    int length;
    char arr[4096];
}train_t;

typedef struct file_message{
    char hash_file[64];//最高支持sha256
    int transed_byte;
    int fd;
    char filename[50];
}file_msg_t;

typedef struct Node{
    struct Node *next_node;
    int id;
}Node_t;

typedef struct Link_list{
    struct Node *head;
    struct Node *tail;
    int length;
}Link_list_t;

int init_train(train_t *train);

int init_file_msg(file_msg_t *msg);


int caculate_hash(char *filepath,char *sha);

int recv_train(int netfd,train_t *train);

int push_file(int netfd,char*filename);

int up_file(int sockfd,char *filename);
int down_file(int sockfd,char *filename);


int get_filepath(Link_list_t *catalog,char *path,char *filename);


#endif
